package impl

import (
	"github.com/jinzhu/gorm"
	"go-test/model"
	"go-test/reposiroty/impl"
	"go-test/usercase"
)

// 实现类

type CourseImpl struct {
	db *gorm.DB
}

func NewCourseImpl(
	db *gorm.DB,
) usercase.Course {
	return &CourseImpl{
		db: db,
	}
}

func (c *CourseImpl) CreateCourse(course *model.Course) (int64, error) {
	repository := impl.NewCourseRepository()
	return repository.CreateCourse(course, c.db)
}

func (c *CourseImpl) ListCourse() ([]*model.Course, error) {
	repository := impl.NewCourseRepository()
	return repository.ListCourse(c.db)
}

func (c *CourseImpl) DelCourse(courseId string) (int64, error) {
	repository := impl.NewCourseRepository()
	return repository.DelCourse(courseId, c.db)
}

func (c *CourseImpl) UpdateCourse(courseId, name string) (int64, error) {
	repository := impl.NewCourseRepository()
	return repository.UpdateCourse(courseId, name, c.db)
}
